How to check if module attribute exists?

Hi,

i have a problem, in some formal modules dosen't exist a attribute.

And now i search a method to check if a module attribute exists.

 

Module m
string test = "Test"
string test2 = "Test2"
...
    if ( type(it)=="Formal" )                         
    {
        Folder fold = getParentFolder(it)
        m = read(fullName(it), false) 
        
        print m.test"\n" 
        print m.test2"\n" 
    }

At my second module he says "unknown Module attribute (Test2)"

 

I search something like 

if(!exists(m.test2))

{

// Do something

}


meinhana - Wed Aug 05 07:29:48 EDT 2015

Re: How to check if module attribute exists?
Rolan - Wed Aug 05 08:18:19 EDT 2015

Try

AttrDef ad

if (!null (ad = find(m, test2))) {

Re: How to check if module attribute exists?
meinhana - Wed Aug 05 08:30:26 EDT 2015

Thank you, but he go in when the attribute is empty... not when the attribute not exists

Re: How to check if module attribute exists?
JohnEarnshaw - Wed Aug 05 11:19:30 EDT 2015

Hi Meinhana,

 

You can also use the following command in your if statement:

if(!null attribute "insert the name of the attribute here"){

You won't have to declare an extra variable and thus will save memory. Hope that helps

Re: How to check if module attribute exists?
llandale - Wed Aug 05 18:37:32 EDT 2015

string NameAttr = "Whatever"

Module m = current

AttrDef ad = find(m, NameAttr)

if (null ad) then NameAttr doesn't exist in the module (or you lack "R"ead rights)

elseif(!ad.module) then NameAttr exists but it is not defined to contain a "Module" value

else Value = m.NameAttr

-Louie

Re: How to check if module attribute exists?
meinhana - Thu Aug 06 03:07:24 EDT 2015

llandale - Wed Aug 05 18:37:32 EDT 2015

string NameAttr = "Whatever"

Module m = current

AttrDef ad = find(m, NameAttr)

if (null ad) then NameAttr doesn't exist in the module (or you lack "R"ead rights)

elseif(!ad.module) then NameAttr exists but it is not defined to contain a "Module" value

else Value = m.NameAttr

-Louie

Thank you, exactly what i need :)

Re: How to check if module attribute exists?
llandale - Thu Aug 06 11:57:28 EDT 2015

Rolan - Wed Aug 05 08:18:19 EDT 2015

Try

AttrDef ad

if (!null (ad = find(m, test2))) {

You can put an assignment statement inside an "if" condition?  Golly where have I been.

I don't think you should want to however; makes the code confusing.

-Louie